package Gui;

import java.awt.BorderLayout;
import java.util.List;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import DAO.*;

public class TableShow extends javax.swing.JFrame{
		public TableShow(List<Student> list)
		{
			initComponents(list);
			
		}
		 private void initComponents(List<Student> list) {
			 setLocationRelativeTo(null);
			    int n=list.size();
			 	String [] rowname={ "Stuno", "Name", "Class", "Gender", "Java", "Math", "English"};
				DefaultTableModel model = new DefaultTableModel();
			
				model.setColumnIdentifiers(rowname);
				int i=0;
				while(i<n)
				{
					Vector<Comparable> v=new Vector<Comparable>(6);
					v.add(0,list.get(i).getStunum());
					v.add(1,list.get(i).getName());
					v.add(2,list.get(i).getClasses());
					v.add(3,list.get(i).getGender());
					v.add(4,list.get(i).getScoreList().get(0).getScore());
					v.add(5,list.get(i).getScoreList().get(1).getScore());
					v.add(6,list.get(i).getScoreList().get(2).getScore());
					i++;
					model.addRow(v);
				}
				back = new javax.swing.JButton();
				back.setText("����");
			    back.addActionListener(new java.awt.event.ActionListener() {
			            public void actionPerformed(java.awt.event.ActionEvent evt) {
			                backActionPerformed(evt);
			            }
			        });
				jTable1=new javax.swing.JTable(model);
				jScrollPane1=new javax.swing.JScrollPane(jTable1);
				jTable1.setVisible(true);
				jScrollPane1.setBounds(100,100,400,300);
				jScrollPane1.setVisible(true);
			    panel=new javax.swing.JPanel(new BorderLayout());
			    panel.add(jScrollPane1,BorderLayout.CENTER);
			    panel.add(back,BorderLayout.SOUTH);
				this.add(panel);
				this.setBounds(400,300,500,300);
				setLocationRelativeTo(null);

		 }
		 
		   private void backActionPerformed(java.awt.event.ActionEvent evt) {                                     
		        this.setVisible(false);
		        new Search().setVisible(true);  
		    }  
		 
		 
		  private javax.swing.JScrollPane jScrollPane1;
		  private javax.swing.JTable jTable1;
		  private javax.swing.table.JTableHeader jth;
		  private  javax.swing.JButton  back;
		  private javax.swing.JPanel panel;
}
